/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;
const int maxm = 2e6 + 10;

int T[maxn], lson[maxm], rson[maxm], c[maxm];
string s;
int n, q, tot;

int build(int l, int r)
{
    int root = tot++;
    c[root] = 0;
    if (l != r)
    {
        int mid = (l + r) >> 1;
        lson[root] = build(l, mid);
        rson[root] = build(mid + 1, r);
    }
    return root;
}

int update(int root, int pos, int val)
{
    int newroot = tot++, tmp = newroot;
    c[newroot] = c[root] + val;
    int l = 1, r = n;
    while (l < r)
    {
        int mid = (l + r) >> 1;
        if (pos <= mid)
        {
            lson[newroot] = tot++;
            rson[newroot] = rson[root];
            newroot = lson[newroot];
            root = lson[root];
            r = mid;
        }
        else
        {
            rson[newroot] = tot++;
            lson[newroot] = lson[root];
            newroot = rson[newroot];
            root = rson[root];
            l = mid + 1;
        }
        c[newroot] = c[root] + val;
    }
    return tmp;
}

int query(int root, int pos)
{
    int ret = 0;
    int l = 1, r = n;
    while (pos < r)
    {
        int mid = (l + r) >> 1;
        if (pos <= mid)
        {
            r = mid;
            root = lson[root];
        }
        else
        {
            ret += c[lson[root]];
            root = rson[root];
            l = mid + 1;
        }
    }

    return ret + c[root];
}

int main()
{
    IOS;

    cin >> s;
    tot = 0;
    n = s.length();
    T[n + 1] = build(1, n);

    map<int, int> mp;
    for (int i = n - 1; i >= 0; i--)
    {
        if (mp.find(s[i + 1] - 0) == mp.end())
        {
            T[i] = update(T[i + 2], i + 1, 1);
        }
        else
        {
            int tmp = update(T[i + 2], mp[s[i] - 'a'], -1);
            T[i] = update(tmp, i + 1, 1);
        }
        mp[s[i] - 'a'] = i + 1;
    }

    cin >> q;
    while (q--)
    {
        int op, x, y;
        char tmp, ex;
        cin >> op;
        if (op == 1)
        {
            cin >> x >> ex >> tmp;
            y = tmp - 'a';
            if (mp.find(y) == mp.end())
            {
                T[x] = update(T[x + 1], x, 1);
            }
            else
            {
                int tmp = update(T[x + 1], mp[y], -1);
                T[x] = update(y, x, 1);
            }
        }
        else
        {
            cin >> x >> y;
            printf("%d\n", query(T[x], y));
        }
    }
    getchar();
    getchar();
    return 0;
}
